# coding=utf-8

# @Time : 2019/12/15 15:21
# @Author : zhusc
# @File : logic/depart_logic.py
# @Desc : 部门相关数据处理

class DepartmentLogic:

    def get_department_everyday_sale_info(mysql, department_id, ts_s, ts_e):
        """ 获取部门每日下单情况
        """
        sql_sale_info = "\
        SELECT \
            id, \
            sp_id, \
            num, \
            totle \
        FROM \
            ko_order \
        WHERE \
            type = %d \
        AND cw_date >= '%s' \
        AND cw_date <= '%s' \
        AND `status` IN (4, 5, 6, 9, 10, 11, 12) \
        AND tui_status <> 3 \
        " % (department_id, ts_s, ts_e)
        sale_res = mysql.select(sql_sale_info)
        return sale_res

    def cal_sale_num_amount(department_sale_info):
        """ 根据查询结果计算商品当日的售出数量和售出金额
        """
        sale_info_return = {'sale_num': 0, 'sale_amount': 0.00}
        for info in department_sale_info:
            sale_info_return['sale_num'] += info['num']
            sale_info_return['sale_amount'] += info['totle']
        return sale_info_return
